define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods_manage/goods/index' + location.search,
                    add_url: 'goods_manage/goods/add',
                    edit_url: 'goods_manage/goods/edit',
                    del_url: 'goods_manage/goods/del',
                    multi_url: 'goods_manage/goods/multi',
                    import_url: 'goods_manage/goods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
//                      {field: 'agent_id', title: __('Agent_id')},
//                      {field: 'store_no', title: __('store_no')},
                        {field: 'supplier_id', title: __('供应商')},
                        {field: 'cat_id', title: __('商品分类')},
                        {field: 'goods_name', title: __('Goods_name'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'cost_price', title: __('Cost_price'), operate:'BETWEEN'},
                        {field: 'sku', title: __('Sku'), operate: 'LIKE'},
                        {field: 'master_image', title: __('Master_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
//                      {field: 'content', title: __('Content')},
                        {field: 'unit', title: __('Unit'), operate: 'LIKE'},
                        {field: 'goods_stock', title: __('Goods_stock')},
                        {field: 'sort', title: __('Sort')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('关闭'),"2":__('启用')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
//                      {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
